package com.atguigu.gmall.web.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.feign.search.SearchFeignClients;
import com.atguigu.gmall.search.vo.SearchParamVo;
import com.atguigu.gmall.search.vo.SearchRespVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

@Controller
public class SearchController {

    @Autowired
    SearchFeignClients searchFeignClients;

    @GetMapping("/list.html")
    public String list(SearchParamVo  param , Model model){

        Result<SearchRespVo> searchData = searchFeignClients.search(param);
        SearchRespVo data = searchData.getData();

        //1、检索用的所有参数
        model.addAttribute("searchParam",data.getSearchParam());
        //2、品牌面包屑
        model.addAttribute("trademarkParam",data.getTrademarkParam());
        //3、属性面包屑
        model.addAttribute("propsParamList",data.getPropsParamList());
        //4、品牌列表
        model.addAttribute("trademarkList",data.getTrademarkList());
        //5、属性列表
        model.addAttribute("attrsList",data.getAttrsList());
        //6、url参数
        model.addAttribute("urlParam",data.getUrlParam());
        //7、排序
        model.addAttribute("orderMap",data.getOrderMap());
        //商品集合; 商品数据原来是在MySQL中；需要通过上架操作给es存一份
        model.addAttribute("goodsList",data.getGoodsList());
        //9、页码
        model.addAttribute("pageNo",data.getPageNo());
        //10、总页码
        model.addAttribute("totalPages",data.getTotalPages());


        return "list/index";
    }

}
